var t = getApp(), a = null, e = null;

Page({
    data: {
        isIpx: t.globalData.isIpx,
        choosedTime: "9:30",
        timeOptions: [ {
            name: "9:30",
            value: "1",
            checked: !0
        }, {
            name: "14:30",
            value: "2"
        } ],
        confirmModal: !1
    },
    onLoad: function(t) {
        var a = new Date(), e = a.getFullYear(), n = a.getMonth() + 1, c = a.getDate(), i = [ "日", "一", "二", "三", "四", "五", "六" ];
        this.calculateEmptyGrids(e, n), this.calculateDays(e, n), this.setData({
            cur_year: e,
            cur_month: n,
            cur_day: c,
            weeks_ch: i
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    timeChange: function(t) {
        this.setData({
            choosedTime: t.detail.value
        });
    },
    getThisMonthDays: function(t, a) {
        return new Date(t, a, 0).getDate();
    },
    getFirstDayOfWeek: function(t, a) {
        return new Date(Date.UTC(t, a - 1, 1)).getDay();
    },
    calculateEmptyGrids: function(t, a) {
        var e = this.getFirstDayOfWeek(t, a), n = [];
        if (e > 0) {
            for (var c = 0; c < e; c++) n.push(c);
            this.setData({
                hasEmptyGrid: !0,
                empytGrids: n
            });
        } else this.setData({
            hasEmptyGrid: !1,
            empytGrids: []
        });
    },
    calculateDays: function(t, a) {
        for (var e = [], n = this.getThisMonthDays(t, a), c = new Date().getDate(), i = 1; i <= n; i++) e.push({
            day: i,
            choosed: i == c
        });
        this.setData({
            days: e
        });
    },
    handleCalendar: function(t) {
        var a = t.currentTarget.dataset.handle, e = this.data.cur_year, n = this.data.cur_month;
        if ("prev" === a) {
            var c = n - 1, i = e;
            c < 1 && (i = e - 1, c = 12), this.calculateDays(i, c), this.calculateEmptyGrids(i, c), 
            this.setData({
                cur_year: i,
                cur_month: c
            });
        } else {
            var o = n + 1, s = e;
            o > 12 && (s = e + 1, o = 1), this.calculateDays(s, o), this.calculateEmptyGrids(s, o), 
            this.setData({
                cur_year: s,
                cur_month: o
            });
        }
    },
    tapDayItem: function(t) {
        var a = t.currentTarget.dataset.idx, e = this.data.days;
        e.forEach(function(t) {
            t.choosed = !1;
        }), e[a].choosed = !e[a].choosed, this.data.cur_day = e[a].day, this.setData({
            days: e,
            cur_day: this.data.cur_day
        }), console.log(this.data);
    },
    chooseYearAndMonth: function() {
        var t = this.data.cur_year, n = this.data.cur_month;
        a = this.data.cur_year, e = this.data.cur_month;
        for (var c = [], i = [], o = 1900; o <= 2100; o++) c.push(o);
        for (var s = 1; s <= 12; s++) i.push(s);
        var r = c.indexOf(t), u = i.indexOf(n);
        this.setData({
            picker_value: [ r, u ],
            picker_year: c,
            picker_month: i,
            showPicker: !0
        });
    },
    pickerChange: function(t) {
        var n = t.detail.value;
        a = this.data.picker_year[n[0]], e = this.data.picker_month[n[1]], console.log(a, e);
    },
    tapPickerBtn: function(t) {
        var n = {
            showPicker: !1
        };
        "confirm" === t.currentTarget.dataset.type && (n.cur_year = a, n.cur_month = e, 
        this.calculateEmptyGrids(a, e), this.calculateDays(a, e)), this.setData(n);
    },
    closeModal: function() {},
    openModal: function() {
        wx.showModal({
            title: "确认已选档期",
            content: "2017年10月26日（周四）",
            showCancel: !0,
            cancelText: "再看看",
            cancelColor: "#C2A469",
            confirmText: "确认",
            confirmColor: "#259B24",
            success: function(t) {},
            fail: function(t) {},
            complete: function(t) {}
        });
    },
    confirmHandler: function() {
        wx.navigateTo({
            url: "/pages/order-detail/order-detail",
            success: function(t) {},
            fail: function(t) {},
            complete: function(t) {}
        }), this.setData({
            confirmModal: !1
        });
    }
});